package com.java.example.ui.dialog

import android.app.AlertDialog
import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import com.java.example.R

class PermissionUserDialog {
    private var mDialog: AlertDialog? = null
    fun showDialog(context: Context?, contentText: String?, onCommit: () -> Unit) {
        mDialog = AlertDialog.Builder(context, -1).create()
        mDialog!!.setCanceledOnTouchOutside(false)
        mDialog!!.show()
        mDialog!!.window?.let {
            it.setContentView(R.layout.permission_user_dialog)
            it.setGravity(Gravity.CENTER)
//            it.setWindowAnimations(R.style.anim_panel_up_from_bottom)
            //设置属性
            val params = it.attributes
            params.width = WindowManager.LayoutParams.MATCH_PARENT
            it.setAttributes(params)
            it.findViewById<TextView>(R.id.content).apply { text = contentText }
            it.findViewById<View>(R.id.save_btn).setOnClickListener {
                onCommit.invoke()
                mDialog!!.dismiss()
            }
        }
    }

    companion object {
        fun create(): PermissionUserDialog {
            return PermissionUserDialog()
        }
    }
}
